package com.chx.three.mama.utils;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.chx.three.mama.R;
import com.chx.three.mama.model.City;
import com.chx.three.mama.model.District;
import com.chx.three.mama.model.Province;

import java.util.ArrayList;
import java.util.List;

/**
 * 可以从这里获取城市数据列表
 */
public class CityUtils {
    /**
     * 获取省份
     * @param context
     * @return
     */
    public static List<Province> getPro(Context context){
        List<Province> pros=new ArrayList<>();
        String province = context.getResources().getString(R.string.province);
        pros=JSON.parseArray(province,Province.class);
        return pros;
    }

    /**
     * 相关省份的城市
     * @param context
     * @param proId
     * @return
     */
    public static List<City> getCitys(Context context,int proId){
        List<City> citys=new ArrayList<>();
        String city = context.getResources().getString(R.string.city);
        List<City> cityList = JSON.parseArray(city, City.class);
        for (City c : cityList) {
            if(c.getProID()==proId){
                citys.add(c);
            }
        }
        return citys;
    }

    /**
     * 获取相关城市的地区
     * @param context
     * @param cityID
     * @return
     */
    public static List<District> getDistrict(Context context,int cityID){
        List<District> districts=new ArrayList<>();
        String district = context.getResources().getString(R.string.distinct);
        List<District> districtList = JSON.parseArray(district, District.class);
        for (District d : districtList) {
            if(d.getCityID()==cityID){
                districts.add(d);
            }
        }
        return districts;
    }
}
